main
sub main()
	dim doc
	Set doc = Application.ActiveDocument
	ValidateServer(doc)
	kUnits = epcbUnitCurrent
	'kUnits = epcbUnitDatabase
	kNumDig = 0

	Application.LockServer

	doc.UnSelectAll

	Application.Gui.StatusBarText "Searching for duplicate vias..."
	Set dictVias = CreateObject("Scripting.Dictionary")
	iCount = 0
	For Each V In doc.Vias(0)
		sViaString = FormatNumber(V.PositionX(kUnits),kNumDig) & "," & FormatNumber(V.PositionY(kUnits),kNumDig) & "," & CStr(V.StartLayer) & "," & CStr(V.EndLayer)
		If dictVias.Exists(sViaString) Then
			V.Delete
			iCount = iCount + 1
		Else
			dictVias.Add sViaString, V
		End If
	Next
	Application.Gui.StatusBarText "Finished deleting " & iCount & " duplicate vias"
	msgbox "Finished deleting " & iCount & " duplicate vias"
end sub
Private Function ValidateServer(doc)    
    Dim key, licenseServer, licenseToken
    key = doc.Validate(0)
    ' Get license server
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    ' Ask the license server for the license token
    licenseToken = licenseServer.GetToken(key)
    ' Release license server
    Set licenseServer = Nothing
    ' Turn off error messages.  Validate may fail if the token is incorrect
    On Error Resume Next
    Err.Clear

    ' Ask the document to validate the license token
    doc.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else
        ValidateServer = 1
    End If
End Function